script_enemy_main{

let shot1=0;
let bullet1=[];
let timer1=[];
let angle1=[];
let radius1=[];

let angle=rand(0,360);

let shots=0;
let oldx=0;
let type=GetArgument;

let damagerate=10;
let outfit=4;
outfit=(128*outfit)-128;
let usespell=0;
let frame=0;
let time=0;
let miny=GetClipMinY; let maxy=GetClipMaxY; let minx=GetClipMinX; let maxx=GetClipMaxX;
let cx=GetCenterX; let cy=GetCenterY;

let SEshotm2=("script\SoundEffects\shotm2.wav");
let SEshotb5=("script\SoundEffects\shotb5.wav");
let SEdeath=("script\SoundEffects\enemydeath1.wav");

let GRboss=("\script\Images\CharacterSprites\Ryo.png");

@Initialize{
	LoadGraphic("\script\Images\CharacterSprites\Ryo.png");

	LoadSE("script\SoundEffects\enemydeath1.wav");
	LoadSE("script\SoundEffects\shotm2.wav");
	LoadSE("script\SoundEffects\shotb5.wav");

	SetScore(100);
	SetLife(20);
	if(GetCommonData("PlayerType")==1){ SetLife(GetLife*0.9); }
	if(GetCommonData("PlayerType")==2){ SetLife(GetLife*1.1); }
	SetDamageRate(10,10);

	SetAngle(90+rand(-120,120));
	SetSpeed(rand(2,3)+0.5*cos(GetAngle*2));
}
	
@MainLoop{

SetCollisionA(GetX,GetY,16);
SetCollisionB(GetX,GetY,16);

if(GetCommonData("PlayerType")==1){ SetDamageRate(10,10); }
if(GetCommonData("PlayerType")==2){ SetDamageRate(13,10); }
if(GetCommonData("PlayerType")==3){ SetDamageRate(8,10); }
if(GetCommonData("PlayerType")==4){ SetDamageRate(12,10); }
if(GetCommonData("PlayerType")==5){ SetDamageRate(8,10); }


if(type==1){
if(time%60==0 && GetX<oldx+0.3 && GetX>oldx-0.3){
let angletoplayer=atan2(GetPlayerY-GetY,GetPlayerX-GetX);
	loop(22){
	CreateShot02(GetX,GetY,8,angletoplayer,-0.1,4,72,0);
	angletoplayer+=360/22;
	}
usespell=20;
PlaySE(SEshotm2);
}
} //type 1

//=======================================

if(type==2){
if(time%14==0 && GetX<oldx+0.3 && GetX>oldx-0.3){
	loop(2){
	CreateShot02(GetX,GetY,8,angle,-0.2,3,83,0);
	angle+=360/2;
	}
angle+=35;
usespell=20;
PlaySE(SEshotm2);
}
} //type 2

//=======================================

if(type==3){
if(time%35==0 && GetX<oldx+0.3 && GetX>oldx-0.3){
	CreateShot02(GetX,GetY,6,90,-0.1,3,37,0);
usespell=20;
PlaySE(SEshotm2);
}
} //type 3

//=======================================


if(time<180){
	if(GetSpeed>0){ SetSpeed(GetSpeed-0.05); }
	if(GetSpeed<0){ SetSpeed(0); }
}
if(time>=180){
let angletoboss=atan2(GetCommonData("Boss1Y")-GetY,GetCommonData("Boss1X")-GetX);
	SetAngle(angletoboss);
	if(GetSpeed<2){ SetSpeed(GetSpeed+0.03); }
if((((GetCommonData("Boss1X")-GetX)^2+(GetCommonData("Boss1Y")-GetY)^2)^0.5)<10){ VanishEnemy; }
}


time++;
frame++;

oldx=GetX;

if(usespell>0){ usespell--; }
if(usespell<0){ usespell++; }
}

@BackGround{
}

@DrawLoop{
	SetGraphicScale(1,1);
	SetTexture(GRboss);
	SetGraphicAngle(0,0,0);
	SetColor(50,50,50);
	SetAlpha(200);
	SetRenderState(ALPHA);

	if(usespell>=1){ SetGraphicRect(384,outfit,512,outfit+128); }
	if(usespell<=-1){ SetGraphicRect(512,outfit,640,outfit+128); }
	if(usespell==0){
		if(GetX<oldx+0.3 && GetX>oldx-0.3){ SetGraphicRect(0,outfit,128,outfit+128); }
		else if(GetX<oldx+0.3){ SetGraphicRect(128,outfit,256,outfit+128); }
		else if(GetX>oldx-0.3){ SetGraphicRect(256,outfit,384,outfit+128); }
	}
	DrawGraphic(GetX,GetY);
}

@Finalize{
if(BeVanished==false){ PlaySE(SEdeath); SetCommonData("FamiliarDestroyed",1); }
}

}